<template>
    <!-- <div>
            <van-search v-model="value" placeholder="请输入搜索关键词"  @search="findGoods()"></van-search>
        </div> -->
    <div class="menu-list">
        <div v-for="item in list" :key="item.id">
            <div class="time">
                <span></span>
                <span
                    >交易成功&nbsp;&nbsp;|&nbsp;&nbsp;<van-icon
                        name="delete-o"
                        @click="deleteGoods(item.id)"
                /></span>
            </div>
            <div @click="todetail(item.id)">
                <!-- desc="02月10日提货" -->
                <!-- num="2" -->
                <van-card
                    :price="item.price"
                    :title="item.shop"
                    :thumb="item.picture"
                >
                    <template #num>
                        <van-button
                            round
                            color="#ED0D5B"
                            plain
                            size="small"
                            type="danger"
                            @click="comment(item.id)"
                            >查看详情</van-button
                        >
                    </template>
                    <template #desc>
                        订单编号：{{ item.number }} <br>
                        <span>订单内容:{{  }}</span>
                        交易金额： ￥{{ item.total_price }} <br>
                        交易时间: {{ item.date }}
                    </template>
                    
                </van-card>
            </div>
            <hr />
        </div>
    </div>
</template>

<script setup lang="ts">
// import {RequestGoodsList} from '@/api/goods'
import { type Ref, ref, onMounted } from 'vue'
// import type {IGoods} from '@/types/types'
// import {RequestSearchList } from '@/api/search.ts'
import { usePyStore } from '@/stores/pyok'
import { useCartStore } from '@/stores/cart'
import { Toast } from 'vant'
import { useRouter } from 'vue-router'
import axios from 'axios'
import { useAccountStore } from '@/stores/user'
const accountStore = useAccountStore()

const comment = (id) => {
    router.push({ path: '/comment', query: { id } })
}

onMounted(() => {
    getAllOrder()
})
// 获取所有订单列表
const getAllOrder = async () => {
    const data = await axios({
        method: 'get',
        url: 'http://localhost:3000/goods/allorder',
        //post请求参数使用data选项, get参数 params选项
    })
    const { code, info } = data.data
    if (code === 1) {
        // accountStore.account
        list.value = info.list.filter(item => {
            if (item.user == accountStore.account.username) return item
        })
        console.log(list.value)
    } else {
        Toast('erro')
    }
}

const router = useRouter()

const usepyok = usePyStore()
const useCart = useCartStore()
// const value = ref('')
const list: Ref<Array<any>> = ref([])

// list.value = usepyok.list
// 删除
const deleteGoods = (id: number) => {
    // const index = list.value.findIndex(item => item.id == id)
    // list.value.splice(index, 1)
}
// 再次购买方法
const buytoo = (item: any) => {
    useCart.saveCart(item)
    Toast('加入购物车成功')
}
// 商品详情
const todetail = (id: number) => {
    // router.push({ path: '/detail', query: { id } })
}
</script>

<style scoped lang="scss">
.menu-list {
    margin-top: 10px;
    width: 100%;
    display: flex;
    justify-content: space-around;
    flex-direction: column;

    .time {
        padding: 5px 24px 5px 24px;
        display: flex;
        justify-content: space-between;
        background-color: #ffffff;
    }

    .time2 {
        padding: 5px 24px 5px 24px;
        display: flex;
        justify-content: space-between;
        background-color: #ffffff;

        .redsapn {
            color: red;
        }
    }
    .van-button {
        float: right;
    }
}
</style>
